package com.jic.veteran.controller;

import com.google.common.collect.Maps;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.dto.AlumniAddEnterpriseParam;
import com.jic.veteran.model.AlumniEnterpriseInformation;
import com.jic.veteran.service.AlumniEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 文章管理controller
 * Created by mars on 2021/11/23.
 */
@RestController
@Api(tags = "AlumniEnterpriseController",description = "学校信息")
@RequestMapping("/enterprise")
public class AlumniEnterpriseController {

    @Autowired
    private AlumniEnterpriseService alumniEnterpriseService;


    @ApiOperation("新闻分页")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Map<String, List<AlumniEnterpriseInformation>>> getPageNews(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                                    @RequestParam(value = "enterpriseName", defaultValue = "") String enterpriseName,
                                                                                    @RequestParam(value = "status", defaultValue = "3") Integer status
    ) {

        List<AlumniEnterpriseInformation> alumniEnterpriseInformation = alumniEnterpriseService.getPage(pageSize,pageNum,enterpriseName,status);
        Map<String, List<AlumniEnterpriseInformation>> map = Maps.newHashMapWithExpectedSize(20);
        map.put("list", alumniEnterpriseInformation);
        return CommonResult.success(map);
    }


    @ApiOperation("更改企业展示状态")
    @RequestMapping(value = "/upstatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult upEnterpriseStatus(@RequestParam(value = "id", required = true) Integer id,
                                        @RequestParam(value = "status", required = true) Integer status
    ) {

        int count = alumniEnterpriseService.upEnterpriseStatus(id,status);
        return CommonResult.success(null);
    }

    @ApiOperation("新增企业")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addEnterprise(@RequestBody AlumniAddEnterpriseParam alumniAddEnterpriseParam) {

        int count = alumniEnterpriseService.addEnterprise(alumniAddEnterpriseParam);
        return CommonResult.success(null);
    }


    @ApiOperation("修改企业信息")
    @RequestMapping(value = "/adit/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult aditEnterprise(@PathVariable Integer id, @RequestBody AlumniAddEnterpriseParam alumniAddEnterpriseParam) {

        int count = alumniEnterpriseService.aditEnterprise(id,alumniAddEnterpriseParam);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除企业")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult deleteEnterprise(@PathVariable Integer id) {

        int count = alumniEnterpriseService.deleteEnterprise(id);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
